import os
import pathlib
 
 
def get_all(path:pathlib.Path, min_size, max_size):
    file_names = os.listdir(path)
    for file_name in file_names:
        file_name_path = path/file_name
        if file_name_path.is_dir():
            # print('文件夹', file_name_path)
            get_all(file_name_path, min_size, max_size)
        else:
            # print('文件', file_name_path)
            size = os.path.getsize(file_name_path)
            print(f"{file_name_path}: {size}",end='\r')
            if min_size <= int(size) <= max_size:
                print('发现大文件', file_name_path)
                with open(pathlib.Path()/'big_file.txt', 'a+', encoding='utf-8') as f:
                    f.write(str(file_name_path))
                    f.write('\n')
 
 
if __name__ == '__main__':
    # 查找 D:\\目录下所有 文件大小在 100M-1G 之间的文件
    get_all(path=pathlib.Path(), min_size=100 * 1024 * 1024, max_size=100*1024 * 1024 * 1024)